<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>任务列表</title>
 <link rel="stylesheet" type="text/css" href="http://192.168.2.92/static/layui/css/layui.css">
  <script src="http://192.168.2.92/static/layui/layui.js"></script>
 <script src="http://192.168.2.92/static/js/jquery-1.11.3.min.js"></script>

    <style>
        #tableshow {
            width: 100%;
            padding-top: 2%;
            padding-left: 20px;
        }
    </style>
</head>
<body class="layui-layout-body">
<div id="tableshow">
    <a href="../ci/static/html/addtask.html">
        <button id="submit" type="button" class="layui-btn layui-btn-primary">增加任务</button>
    </a>
    <table id="demo" lay-filter="test"></table>
</div>
 
<script type="text/html" id="barDemo">
             <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
             <a id="deletebtn" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>

<script>
    $(document).ready(function () {
        var list = {};
        var getAllTask = function (x) {
            $.ajax({
                //请求方式
                type: "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                // url: "http://127.0.0.1/tasklist/",
                url: "tasklist",
                //数据，json字符串
                data: JSON.stringify(list),
                //请求成功
                success: function (result) {
                    alert("sadfasdfasf")
                    alert(result)
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });
        }
    });
</script>


<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            id: "demo",
            title: '任务列表',
            elem: '#demo',
            url: 'tasklist',
            page: true,
            limits: [3, 5, 10],
            limit: 10,
            cols: [[
                {field: 'id', title: 'ID', sort: true, width: 100, fixed: 'left'}
                , {field: 'task_name', title: '任务名称'}
                , {field: 'job_name', title: '工作名称'}
                , {field: 'ding_token', title: 'token'}
                , {field: 'create_time', title: '创建时间', sort: true}
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#barDemo'}
            ]],
            parseData: function (res) {
                var result;
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                } else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            }
        });
    });
</script>
<script>

    layui.use('table', function () {
        //创建table
        var table = layui.table;
        //监听工具条
        table.on('tool(test)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var kk = data['id'];  //获取属性uid的值

            if (obj.event === 'detail') {
                layer.open({
                    title: '任务详情',
                    type: 2,
                    maxmin: true,
                    shade: [0.8, '#393D49'],
                    area: ['700px', '570px'],
                    content: "../static/html/taskdetails.html",
                });
            } else if (obj.event === 'edit') {
                var edit_button = data["id"]
                layer.open({
                    title: '编辑详情',
                    type: 2,
                    shadeClose: true,
                    shade: [0.8, '#393D49'],
                    maxmin: true,
                    area: ['90%', '90%'],
                    content: "../ci/static/html/taskedit.html?id=" + edit_button,
                    cancel: function (index, layero) {
                        window.location.reload()
                    }
                });
            } else {
                layer.confirm('确认删除么', function (index) {
                    $.ajax({
                        url: "deletetastone",
                        data: {id: data['id']},
                        type: "get",
                        dataType: 'json',
                        success: function (data) {

                            if (data.code === "0") {
                                layer.msg('别再点了，已经被删了', {time: 800});
                                table.reload('demo', {});
                            } else {
                                layer.alert(message, {
                                    icon: 2, title: '提示'
                                });
                                return;
                            }
                        },
                        error: function () {
                        }
                    })
                });
            }

        })
    })

</script>


</body>
</html>
































































